#include"p2p.h"
/*#include <stdio.h>
#include <sys/types.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <linux/sockios.h>
#include <sys/ioctl.h>
#include <arpa/inet.h>
#include <string.h>
*/
int getip(char *ipp)
{
int s;
struct ifconf conf;
struct ifreq *ifr;
char buff[BUFSIZ];
char  *ip;
int num;
int i, n, len;
char port[] = ",210,53";

s = socket(PF_INET, SOCK_DGRAM, 0);
conf.ifc_len = BUFSIZ;
conf.ifc_buf = buff;

ioctl(s, SIOCGIFCONF, &conf);
num = conf.ifc_len / sizeof(struct ifreq);
ifr = conf.ifc_req;

for(i=0;i < num;i++)
{
	struct sockaddr_in *sin = (struct sockaddr_in *)(&ifr->ifr_addr);
	ioctl(s, SIOCGIFFLAGS, ifr);
	if(((ifr->ifr_flags & IFF_LOOPBACK) == 0) && (ifr->ifr_flags & IFF_UP))
	{
		ip = inet_ntoa(sin->sin_addr);
		strcpy(ipp, ip);
		len = strlen(ipp);
		for(n = 0; n < len; n++)
		{if(ipp[n] == '.')
			ipp[n] = ',';
		}
		strcpy(ipp+len, port);
		printf("%s (%s) %d\n",
		ifr->ifr_name,
		ipp, strlen(ipp));
	}
	ifr++;
}
	return 0;
}


/*int main(void)
{	
	int a = 78875094;
	char ipp[30];
	getip(ipp);
	printf("%s %x\n", ipp, a);
	return 0;
}*/
